"""
补充代码中的 singleton 函数，
使其装饰的 Test 类成为一个单例类
"""

def singleton(cls, *args, **kargs):
    """
    实现一个单例装饰器
    """
    _instance_dict = {}
    def _singleton():
        if cls not in _instance_dict:
            _instance_dict[cls] = cls(*args, **kargs)
        return _instance_dict[cls]

    return _singleton

@singleton
class Test:
    pass

test1 = Test()
test2 = Test()

assert test1 is test2, "不是单例"


